
const commonConfig = require('./commonPreload.js');
const globalValue = require('./global.js');

const codes = ['windowsPath', 'windowsPathRight', "windowsPathLinux","windowsPathWsl"];
const featureCode = codes.reduce((pre, current) => {
  return {
    ...pre, [current]: {
      ...commonConfig,
      args: {
        ...commonConfig.args,
        enter: (action) => {
          console.log('action', action)
          if (['wpathl', 'wpathr','wpathx', 'wpathwsl'].includes(action.payload)) {
            window.utools.setSubInput(({ text }) => {
              commonConfig.args.enter({ ...action, type: 'text', code: current, text })
            }, '直接输入即可实时变更')
            return
          }
          window.utools.hideMainWindow()
          commonConfig.args.enter({ ...action, code: current })
          window.utools.outPlugin()
        }
      }
    }
  }
}, {})
window.exports = {
  ...featureCode,
  'wpath': {
    mode: 'list',
    args: {
      // 进入插件时调用（可选）
      enter: (action, callbackSetList) => {
        // 如果进入插件就要显示列表数据
        callbackSetList([
          {
            title: '转换为双左斜杠',
            description: '路径转换为双左斜杠路径',
            code: 'windowsPath',
          },
          {
            title: '转换为右斜杠',
            description: '路径转换为右斜杠路径',
            code: 'windowsPathRight'
          }
        ])
      },
      // // // 子输入框内容变化时被调用 可选 (未设置则无搜索)
      // search: (action, searchWord, callbackSetList) => {
      //   console.log('action', action, searchWord)
      //   // 获取一些数据
      //   // 执行 callbackSetList 显示出来

      // },
      // 用户选择列表中某个条目时被调用
      select: (action, itemData, callbackSetList) => {
        let init = false;
        window.utools.setSubInput(({ text }) => {
          commonConfig.args.enter({ ...itemData, type: 'text', text, noCheck: !init })
          globalValue.currentText = text
          init = true
        }, '直接输入即可实时变更')
        globalValue.currentText && window.utools.setSubInputValue(globalValue.currentText)
      },
      // 子输入框为空时的占位符，默认为字符串"搜索"
      placeholder: "选择转换方法"
    }


  }
}